<script setup lang="ts">
import { useRouter } from 'vue-router'
const router = useRouter()
const gotoHome = () => {
  router.push({
    name: 'Home',
  })
}
import { useUserStore } from '@/store/modules/userStore'
import { storeToRefs } from 'pinia'
const userStore = useUserStore()
/**打开登录对话库框 */
const showLogin = () => {
  userStore.visiable = true
}
const { userInfo } = storeToRefs(userStore)
/** 用户退出登录 */
const outLogin = () => {
  userStore.outLogin()
  router.replace('/')
}
/** 点击菜单 */
const commandChange = (command: string | number | object) => {
  switch (command) {
    case '0':
      router.push('/user/autonym')
      break
    case '1':
      router.push('/user/order')
      break
    case '2':
      router.push('/user/patient/patient_list')
      break
    case '3':
      outLogin()
      break
    default:
      console.log('其他操作')
  }
}
</script>

<template>
  <div class="hospital_top">
    <div class="content">
      <!-- 左侧 -->
      <div class="content_left" @click="gotoHome">
        <img src="../../assets/Svg/login_successfully.svg" alt="logo" />
        <span>医疗在线 预约挂号平台</span>
      </div>
      <!-- 右侧 -->
      <div class="content_right">
        <span class="help">帮助中心</span>
        <el-dropdown v-if="userInfo.token" class="login" @command="commandChange">
          <span class="el-dropdown-link">
            {{ userInfo.name }}
            <el-icon>
              <arrow-down />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="0">实名认证</el-dropdown-item>
              <el-dropdown-item command="1">挂号订单</el-dropdown-item>
              <el-dropdown-item command="2">就诊人管理</el-dropdown-item>
              <el-dropdown-item command="3">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
        <span v-else class="login" @click="showLogin">登录/注册</span>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.hospital_top {
  width: 100%;
  height: $hospital_top;
  display: flex;
  justify-content: center;
  position: fixed;
  z-index: 999;
  background-color: #fff;
  box-shadow: 0 0 10px 0 rgba(29, 26, 26, 0.1);
  .content {
    width: $container_width;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .content_left {
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      img {
        height: 50px;
        width: 50px;
        margin-right: 10px;
      }
      span {
        font-size: 20px;
        color: #89b4dd;
      }
    }
    .content_right {
      display: flex;
      justify-content: center;
      align-items: center;
      .help {
        font-size: 14px;
        color: #a7b5c1;
        cursor: pointer;
      }
      .login {
        margin-left: 12px;
        color: #a7b5c1;
        font-size: 14px;
        cursor: pointer;
      }
    }
  }
}
</style>
